//
//  OrderDetailViewController.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/18.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "LHSelectedNavigationViewTools.h"
#define kWidth self.view.frame.size.width
#define kHeight self.view.frame.size.height
#import "OrderDetailCollectionReusableViewHeader.h"
#import "OrderDetailFirstCollectionViewCell.h"
#import "OrderDetailSecondCollectionViewCell.h"
#import "OrderDetailThirdCollectionViewCell.h"
@interface OrderDetailViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)LHSelectedNavigationViewTools *tools; //分段选择器
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)UICollectionViewFlowLayout *flowLayout;
@end

@implementation OrderDetailViewController

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        _flowLayout = [[UICollectionViewFlowLayout alloc]init];
        _flowLayout.minimumLineSpacing = 0;
        _flowLayout.minimumInteritemSpacing = 0;
        _flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 114, kWidth, kHeight - 124) collectionViewLayout:self.flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        //注册cell
        [_collectionView registerNib:[UINib nibWithNibName:@"OrderDetailFirstCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"OrderDetailFirstCollectionViewCell"];
        [_collectionView registerNib:[UINib nibWithNibName:@"OrderDetailSecondCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"OrderDetailSecondCollectionViewCell"];
        [_collectionView registerNib:[UINib nibWithNibName:@"OrderDetailThirdCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"OrderDetailThirdCollectionViewCell"];

        //注册头视图
        [_collectionView registerNib:[UINib nibWithNibName:@"OrderDetailCollectionReusableViewHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"OrderDetailCollectionReusableViewHeader"];
    }
    return _collectionView;
}

- (LHSelectedNavigationViewTools *)tools{
    if (!_tools) {
        NSArray *listArr = [NSArray arrayWithObjects:@"全部",@"待付款",@"待发货",@"待收货",@"待评价", nil];
        _tools = [[LHSelectedNavigationViewTools alloc]initLHSelectedNavigationViewToolsWithFrame:CGRectMake(0, 63, kWidth, 50) ButtonTitle:listArr];
    }
    return _tools;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的订单";
    [self.view addSubview:self.tools];
    [self.view addSubview:self.collectionView];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        OrderDetailFirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OrderDetailFirstCollectionViewCell" forIndexPath:indexPath];
        return cell;
    }else if (indexPath.row == 1){
        OrderDetailSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OrderDetailSecondCollectionViewCell" forIndexPath:indexPath];
        return cell;
    }else{
        OrderDetailThirdCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OrderDetailThirdCollectionViewCell" forIndexPath:indexPath];
        return cell;
    }
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        OrderDetailCollectionReusableViewHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"OrderDetailCollectionReusableViewHeader" forIndexPath:indexPath];
        return headerView;
    }else{
        return nil;
    }
}
//item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 || indexPath.row == 2) {
        return CGSizeMake(kWidth, 100);
    }else{
        return CGSizeMake(kWidth, 60);
    }
}
//头视图大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(kWidth, 50);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
